/*
 * Copyright (c) 2017 22420103@QQ.COM 版权所有
 */
package com.lehe.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lehe.common.MessageEnumDto;
import com.lehe.entry.AgentInfoDto;
import com.lehe.entry.UserInfoDto;
import com.lehe.service.impl.AgentInfoService;
import com.lehe.service.impl.UserInfoService;

/**
 * 代理管理
 *
 * @author 王丹
 * @since 2017-02-26
 */
@Controller
@RequestMapping("agent")
public class AgentManagerController extends Basecontroller{

    @Autowired
    private AgentInfoService agentInfoService;
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 授权代理首页
     * @return
     */
    @RequestMapping
    public String index(){
        return "user/auth";
    }
    
    @RequestMapping("charge")
    public String charge(Model m){
    	UserInfoDto dto = userInfoService.queryUserInfo(this.getUserId(), null);
    	m.addAttribute("myCount", dto.getGoldCoinCount());
        return "user/charge";
    }

    /**
     * 授权玩家信息查询
     * @param uid
     * @return
     */
    @RequestMapping("query")
    @ResponseBody
    public UserInfoDto query(@RequestParam(value="uid") Long uid){
        UserInfoDto userInfoDto = userInfoService.queryUserInfo(uid, null);
        if(userInfoDto == null){
            userInfoDto = new UserInfoDto();
        }
        return userInfoDto;
    }
    
    /**
     * 
     * @param uid
     * @param pwd
     * @param mobile
     * @return
     */
    @RequestMapping("charge/confrim")
    @ResponseBody
    public MessageEnumDto chargeConfrim(@RequestParam(value="uid") Long uid,Integer count){
      
        return agentInfoService.charge(this.getUserId(), uid,count);
    }
    
    /**
     * 确定授权操作
     * @param uid
     * @param pwd
     * @param mobile
     * @return
     */
    @RequestMapping("auth")
    @ResponseBody
    public MessageEnumDto authAgent(@RequestParam(value="uid") Long uid, String pwd, String mobile){
        //TODO: 手机号码验证和密码验证
        AgentInfoDto agentInfoDto = new AgentInfoDto();
        agentInfoDto.setUserId(uid);
        agentInfoDto.setAgentPassword(pwd);
        agentInfoDto.setPhoneNum(mobile);
        return agentInfoService.createAgent(this.getUserId(), agentInfoDto);
    }
}
